package com.smartkey.app;

import android.app.Application;
import android.content.Intent;
import android.content.IntentFilter;

import com.smartkey.receiver.HeadsetPlugReceiver;
import com.smartkey.service.BootService;

public class SmartKeyApplication extends Application {

	private HeadsetPlugReceiver headsetPlugReceiver;

	@Override
	public void onCreate() {
		super.onCreate();
		/* register receiver */
		registerHeadsetPlugReceiver();
		startBootService();
	}

	private void registerHeadsetPlugReceiver() {
		headsetPlugReceiver = new HeadsetPlugReceiver();
		IntentFilter intentFilter = new IntentFilter();
		intentFilter.addAction("android.intent.action.HEADSET_PLUG");
		registerReceiver(headsetPlugReceiver, intentFilter);
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
		// unregisterReceiver(headsetPlugReceiver);
	}

	private void startBootService() {
		Intent service = new Intent();
		service.setClass(this, BootService.class);
		startService(service);
	}
}
